home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Belgian Amiga Club - ADF Collection
/
BS1 part 43.zip
/
ANC 15.adf
/
demo
/
pi.c
< prev
next >
Wrap
C/C++ Source or Header
|
1987-01-01
|
772b
|
45 lines
/* Program pi.c originally distributed by Microsoft to demonstrate Codeview */
/* for IBM PCs and compatibles. Released by Microsoft into the public domain. */
#include <time.h>
#define MAXPRC 4000
char p[MAXPRC];
char t[MAXPRC];
int q;
main(argc,argv)
int argc;
char *argv[];
{
long startime, endtime;
register int i;
if (argc == 2) {
sscanf(argv[1],"%d",&q);
} else {
printf("Usage: pi [precision]\n");
exit(-1);
}
if (q > MAXPRC) {
printf("Precision too large\n");
exit(-1);
}
/* compute pi */
time(&startime);
arctan(2);
arctan(3);
mul4();
time(&endtime);
/* print pi */
printf("pi = %d.",p[0]);
for (i = 1; i <= q; i++)
printf("%d",p[i]);
printf("\n");
printf("%ld seconds to compute %d digits of pi\n",endtime - startime,q);
}